<?php

namespace SDK;

use SDK\Client;
use SDK\BuildClient;
use Constants\StatusCode;
use Exception;

class Info extends Client {
    public $client;
    public $app_id;
    public $app_secret;
    public $base_url;

    public function __construct(Client $client){
        $this->client = $client;
        $this->app_id = $client->app_id;
        $this->app_secret = $client->app_secret;
        $this->base_url = $client->base_url;
    }

    // 获取在线卡设置信息
    public function getDeviceSettingOnlineCardInfo($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceSettingOnlineCardInfo', $queryParams);
        return $this->handleResponse($response);
    }

    // 获取安全设置信息
    public function createCompanyRenewOrder($req){
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $postParams = $commonMethod->build_post_param($req);
        $response = $this->client->post( '/open/device/saveMode', post_params:  $postParams);
        return $this->handleResponse(response: $response);
    }

    // 获取时间模式设置信息
    public function getDeviceModeTimeInfo($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceModeTimeInfo', $queryParams);
        return $this->handleResponse($response);
    }

    // 获取时间模式2设置信息
    public function getDeviceModeTime1Info($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceModeTime1Info', $queryParams);
        return $this->handleResponse($response);
    }

    // 获取投币设置信息
    public function getDeviceSettingCoinInfo($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceSettingCoinInfo', $queryParams);
        return $this->handleResponse($response);
    }


    // 多个设备信息的返回
    public function findMultiDevices($req){
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $postParams = $commonMethod->build_post_param($req);
        $response = $this->client->post( '/open/device/findMultiDevices', post_params:  $postParams);
        return $this->handleResponse(response: $response);
    }

    // 设备添加
    public function deviceAdd($req){
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $postParams = $commonMethod->build_post_param($req);
        $response = $this->client->post( '/open/device/add', post_params:  $postParams);
        return $this->handleResponse(response: $response);
    }


    // 获取电量模式设置信息
    public function getDeviceModeWorkInfo($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceModeWorkInfo', $queryParams);
        return $this->handleResponse($response);
    }

    // 获取电量模式2设置信息
    public function getDeviceModeWork1Info($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceModeWork1Info', $queryParams);
        return $this->handleResponse($response);
    }

    // 获取功率模式设置信息
    public function getDeviceModePowerInfo($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceModePowerInfo', $queryParams);
        return $this->handleResponse($response);
    }


    // 获取功率模式2设置信息
    public function getDeviceModePower1Info($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceModePower1Info', $queryParams);
        return $this->handleResponse($response);
    }


    // 设备列表
    public function deviceFindList($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/findList', $queryParams);
        return $this->handleResponse($response);
    }

    // 设备删除
    public function deviceDel($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/del', $queryParams);
        return $this->handleResponse($response);
    }

    // 获取安全设置信息
    public function deviceSaveMode($req){
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $postParams = $commonMethod->build_post_param($req);
        $response = $this->client->post( '/open/device/saveMode', post_params:  $postParams);
        return $this->handleResponse(response: $response);
    }

    // 获取收费模式信息
    public function deviceGetMode($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getMode', $queryParams);
        return $this->handleResponse($response);
    }

    // 获取用户设置模式信息
    public function getDeviceSettingUserInfo($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceSettingUserInfo', $queryParams);
        return $this->handleResponse($response);
    }


    // 获取免打扰设备信息
    public function getDeviceSettingNotDisturbInfo($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceSettingNotDisturbInfo', $queryParams);
        return $this->handleResponse($response);
    }


    // 设备详情
    public function deviceFindOne($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/findOne', $queryParams);
        return $this->handleResponse($response);
    }

    // 获取离线卡设置信息
    public function getDeviceSettingOfflineCardInfo($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceSettingOfflineCardInfo', $queryParams);
        return $this->handleResponse($response);
    }


    // 获取安全设置信息
    public function getDeviceSettingSafetyInfo($req) {
        $commonMethod = new BuildClient($this->app_id,$this->app_secret); 
        $queryParams = $commonMethod->build_get_param($req);
        $response = $this->client->get(  '/open/device/getDeviceSettingSafetyInfo', $queryParams);
        return $this->handleResponse($response);
    }

    private function handleResponse($response) {
        $jsonString = json_encode($response);
        $data = json_decode($jsonString,true);
        if ($data['code'] !== StatusCode::SucceedCode) {
            throw new Exception($data['message']);
        }
        return $data;
    }
}